#include "comm.hpp"
#include "log.hpp"

int main()
{
    key_t key = ftok(PATH_NAME, PROJ_ID);
    assert(key != -1);
    (void)key;
    log("创建key值成功", DEBUG) << "client:key =" << key << endl;

    // 获取共享内存
    int shmid = shmget(key, SHM_SIZE, 0);
    if (shmid == -1)
    {
        perror("shmget");
        exit(1);
    }
    log("获取共享内存成功", DEBUG) << "shmid =" << shmid << endl;
    sleep(8);

    char *shmaddr = (char *)shmat(shmid, nullptr, 0);
    if (shmaddr == nullptr)
    {
        perror("shmaddr");
        exit(2);
    }
    log("共享内存与地址空间映射建立成功", DEBUG) << "shmid =" << shmid << endl;
    sleep(8);

    // 使用

    
    int ret = shmdt(shmaddr);
    if (ret == -1)
    {
        perror("shmdt");
        exit(3);
    }
    log("共享内存与地址空间去关联成功", DEBUG) << "shmid =" << shmid << endl;

    return 0;
}